package com.codejoys.springmvc.web;

import com.codejoys.springmvc.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Arrays;

@Controller
public class UserController {
    //localhost/home  =>  home.html
    @GetMapping("/home")//请求路径
    public String home(){
        return "home.html";//响应的文件
    }

    /**
     * 使用controller方法的形参，去接收页面表单的输入参数
     * @param username
     * @param password
     * @return
     */
    @PostMapping("/login")
    public String login(@RequestParam("userName") String username, String password){
        System.out.println(username+"/"+password);
        //redirect:请求转发
        return "redirect:success.html";
    }

    @GetMapping("/loginFrom")
    public String loginFrom(){
        return "login.html";
    }

    //pojo封装参数//页面不能访问
    @PostMapping("/register")
//    public String register(User user,String roleId){
    public String register(User user,Integer[] hobbies){
        System.out.println(user);

        System.out.println(user.getRole());
        //role.id=>user.role.id

//        System.out.println("role:"+roleId);

        System.out.println(Arrays.toString(hobbies));

        return "redirect:success.html";
    }

//    //通过方法去访问
    @GetMapping("/registerFrom")
    public String registerFrom(){
        return "register.html";
    }


}
